<?php
/**
 * @class fiasco database model
 * @description base database class for 
 * other databases to implement off 0f
 */

require 'drivers/template.recordset.php';

 abstract class fiasco_database_template
 {	
	/* connect to database */
	abstract static protected function connect();
 
	/**
	 * Query database
	 */
	abstract public function query($SQL);

	protected function prepare($SQL, $args = array()){
		while (preg_match('/(%s|%d|%b|%f)/', $SQL, $match) && count($args)) {
			$SQL = preg_replace("/".$match[1]."/", array_shift($args), $SQL, 1);
		}
		return $SQL;
	}
	
	/**
	 * kill connection
	 */
	abstract static public function kill();
	
 
 }


if (!defined('DB_URL')) { throw new Exception("cannot not define database connection type. DB_URL not present. must be defined in config.php");}

$db_info = (object) parse_url(DB_URL);
switch (strtolower($db_info->scheme)) {
	case 'psql':
	case 'pgsql':
	case 'postgres':
	case 'postgresql':
		require 'drivers/pgsql.driver.php';
	break;
	case 'mysql':
	default:
		require 'drivers/mysql.driver.php';
	break;
}
